package com.ruoyi.eoms.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eoms.domain.Party;
import com.ruoyi.eoms.service.IPartyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户管理Controller
 * 
 * @author yuanpingfang
 * @date 2020-12-01
 */
@RestController
@RequestMapping("/eoms/party")
public class PartyController extends BaseController
{
    @Autowired
    private IPartyService partyService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:list')")
    @GetMapping("/list")
    public TableDataInfo list(Party party)
    {
        startPage();
        List<Party> list = partyService.selectPartyList(party);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Party party)
    {
        List<Party> list = partyService.selectPartyList(party);
        ExcelUtil<Party> util = new ExcelUtil<Party>(Party.class);
        return util.exportExcel(list, "party");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:query')")
    @GetMapping(value = "/{partyId}")
    public AjaxResult getInfo(@PathVariable("partyId") String partyId)
    {
        return AjaxResult.success(partyService.selectPartyById(partyId));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Party party)
    {
        return toAjax(partyService.insertParty(party));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Party party)
    {
        return toAjax(partyService.updateParty(party));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:party:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partyIds}")
    public AjaxResult remove(@PathVariable String[] partyIds)
    {
        return toAjax(partyService.deletePartyByIds(partyIds));
    }
}
